package com.hkts.management.orderimg.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.utils.CustomPageUtils;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.management.orderimg.service.IHktsOrderImgService;
import com.hkts.management.orderimg.entity.HktsOrderImg;

import java.util.List;
import java.util.Map;

/**
 * @author hml
 * @since 2021-04-22
 */
@RestController
@RequestMapping("/order/hktsOrderImg")
@Api(tags = "装卸货图片管理接口")
public class HktsOrderImgController {
    private final Logger logger = LoggerFactory.getLogger(HktsOrderImgController.class);

    @Autowired
    public IHktsOrderImgService iHktsOrderImgService;

    /**
     * 分页查询数据
     *
     * @param page         分页信息
     * @param hktsOrderImg 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsOrderImgPageList")
    public Result<Object> getHontUserList(Page<HktsOrderImg> page, HktsOrderImg hktsOrderImg) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsOrderImgService.selectPage(page, hktsOrderImg)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsOrderImg 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsOrderImgSave")
    public Result<Object> hktsOrderImgSave(HktsOrderImg hktsOrderImg) {
        iHktsOrderImgService.saveOrUpdate(hktsOrderImg);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsOrderImgGetById")
    public Result<Object> hktsOrderImgGetById(String id) {
        HktsOrderImg byId = iHktsOrderImgService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsOrderImgDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsOrderImgService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsOrderImgBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsOrderImgService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    /**
     * 根据订单id，类型获取图片列表
     */
    @ResponseBody
    @GetMapping("/getOrderImg")
    @ApiOperation(value = "根据订单id，类型获取图片列表")
    public Result<Object> getOrderImg(String orderId,Integer type){
        Map<String,Object> maps = iHktsOrderImgService.selectList(orderId,type);
        return ResultUtil.data(maps);
    }
    /**
     * 根据订单id，类型获取图片列表
     */
    @ResponseBody
    @GetMapping("/getOrderImgByRecord")
    @ApiOperation(value = "根据修改记录，类型获取图片列表")
    public Result<Object> getOrderImgByRecordId(String recordId){
        Map<String,Object> maps = iHktsOrderImgService.getOrderImgByRecordId(recordId);
        return ResultUtil.data(maps);
    }

}
